package Module;

import LiftEngine.Lift;
import Server.ClientList;

/**
 *
 * Class description goes here.
 *
 * @author Kamil Gajowy
 */
public class ModuleWorker extends Thread {

    private ModuleSteeringAlgorithm algorithm;
    private Lift liftRef;
    private ClientList clientList;
    private boolean running;
    private ModuleClient moduleClient;

    /**
    * Default constructor.
     * @param name
     * @param liftRef
     * @param cListRef 
     */
    public ModuleWorker(String name, ModuleClient moduleClient){
        super(name);
        //this.liftRef = liftRef;
        //this.clientList = cListRef;
        this.moduleClient = moduleClient;

        this.running = true;
        this.algorithm = new ModuleSteeringAlgorithm();
    }

    public void stopMe(){
        running = false;
        System.out.println("\t\t closing thread " + this.getName());
    }

    @Override
    public synchronized void run(){
        //pre init

        while(running){
            algorithm.update(moduleClient.getLiftRef(),moduleClient.getTaskDone(), moduleClient.getServerTask());

            //rest
            try {
                ModuleWorker.sleep(100);
            }catch(InterruptedException ex){
                System.out.println("Module - Steering - crashed.");
            }
        }

    }

}//end class
